package com.cherish.pattern.prototype.deep;

import java.io.*;
import java.util.Date;

/**
 * @Classname SunWuKong
 * @Date 2019/4/7 13:21
 * @Author admin
 * @Description TODO
 */
public class SunWuKong extends Monkey implements Serializable, Cloneable {

    private JinGuBang jinGuBang;

    public SunWuKong() {
        this.setHeight(120);
        this.setWeight(20);
        this.setDate(new Date());
        this.setJinGuBang(new JinGuBang());
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public SunWuKong deepClone(SunWuKong sunWuKong) {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
            objectOutputStream.writeObject(sunWuKong);

            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            SunWuKong zhexingsun = (SunWuKong) objectInputStream.readObject();
            return zhexingsun;
        } catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public SunWuKong shallowClone(SunWuKong sunWuKong) {
        SunWuKong sunXingZhe = new SunWuKong();
        sunXingZhe.setWeight(sunWuKong.getWeight());
        sunXingZhe.setHeight(sunWuKong.getHeight());
        sunXingZhe.setDate(sunWuKong.getDate());
        sunXingZhe.setJinGuBang(sunWuKong.getJinGuBang());

        return sunXingZhe;
    }


    public JinGuBang getJinGuBang() {
        return jinGuBang;
    }

    public void setJinGuBang(JinGuBang jinGuBang) {
        this.jinGuBang = jinGuBang;
    }
}
